package mobmap.util;
/**
 * Classe com métodos uteis para a manipulação de
 * imagens e/ou quadros dos MAPs
 * 
 * @author ulisses
 *
 */
public class MapUtil {

	private int posVertical;
	private int posHorizontal;

	
	public MapUtil(int posHoriz, int posVer){
		posVertical = posVer;
		posHorizontal = posHoriz;
	}
	
	
	public String getNumImagem(){
		return String.valueOf(Math.ceil(posVertical / Quadro.SIZE)) + String.valueOf(Math.ceil(posHorizontal / Quadro.SIZE));
	}
	
	private int numQuadroH(){
		return new Double(Math.ceil(Math.abs(posHorizontal / Quadro.SIZE))).intValue();
	}
	
	private int numQuadroV(){
		return new Double(Math.ceil(Math.abs(posVertical / Quadro.SIZE))).intValue();
	}
	
	private String conc(int valor1, int valor2){
		return String.valueOf(valor1)+String.valueOf(valor2);
	}
	
	public Quadro[][] getImagensRelativas(){
		
		int posHRelativa = posHorizontal + numQuadroH()*Quadro.SIZE;
		int posVRelativa = posVertical + numQuadroV()*Quadro.SIZE;
		
		int quadroHInicial = numQuadroH();
		int quadroVInicial = numQuadroV();
		
		Quadro quadros[][] = new Quadro[2][2];
		
		quadros[0][0] = new Quadro( posVRelativa, posHRelativa, conc(quadroVInicial, quadroHInicial));
		quadros[0][1] = new Quadro(posVRelativa, posHRelativa + Quadro.SIZE, conc(quadroVInicial, quadroHInicial + 1));
		quadros[1][0] = new Quadro(posVRelativa + Quadro.SIZE, posHRelativa, conc(quadroVInicial + 1, quadroHInicial));
		quadros[1][1] = new Quadro(posVRelativa + Quadro.SIZE, posHRelativa + Quadro.SIZE, conc(quadroVInicial + 1, quadroHInicial + 1));
		
		return quadros;
	}


	public int getPosVertical() {
		return posVertical;
	}


	public void setPosVertical(int posVertical) {
		this.posVertical = posVertical;
	}


	public int getPosHorizontal() {
		return posHorizontal;
	}


	public void setPosHorizontal(int posHorizontal) {
		this.posHorizontal = posHorizontal;
	}
	
}
